﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mes5GService.Migrations
{
    public partial class BopAndStruct : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BopTrees",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BopTrees", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "FileTableDatas",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FieldName = table.Column<string>(nullable: true),
                    DisplayName = table.Column<string>(nullable: true),
                    Enable = table.Column<bool>(nullable: false),
                    Show = table.Column<bool>(nullable: false),
                    Property = table.Column<int>(nullable: false),
                    ColumnType = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileTableDatas", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "FileTables",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FileWorkStepId = table.Column<string>(nullable: true),
                    FileProcessesId = table.Column<string>(nullable: true),
                    StepCheckComplete = table.Column<bool>(nullable: false),
                    StartQualitySignature = table.Column<bool>(nullable: false),
                    TableFieldName = table.Column<string>(nullable: true),
                    TableName = table.Column<string>(nullable: true),
                    DataComplete = table.Column<bool>(nullable: false),
                    DynamicTable = table.Column<bool>(nullable: false),
                    HasInspectionSignature = table.Column<bool>(nullable: false),
                    StartSignatured = table.Column<bool>(nullable: false),
                    Signatured = table.Column<bool>(nullable: false),
                    SortIndex = table.Column<int>(nullable: false),
                    NewTable = table.Column<bool>(nullable: false),
                    DeletedTable = table.Column<bool>(nullable: false),
                    TableChanged = table.Column<bool>(nullable: false),
                    StepDeleted = table.Column<bool>(nullable: false),
                    InspectionSignatureName = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileTables", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "StructColumnTypes",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FieldName = table.Column<string>(nullable: true),
                    ColumnType = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StructColumnTypes", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BopNodes",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    BopTreeId = table.Column<Guid>(nullable: false),
                    BopNodeId = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BopNodes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BopNodes_BopNodes_BopNodeId",
                        column: x => x.BopNodeId,
                        principalTable: "BopNodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BopNodes_BopTrees_BopTreeId",
                        column: x => x.BopTreeId,
                        principalTable: "BopTrees",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FileProcessSpecifications",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    BopTreeId = table.Column<Guid>(nullable: false),
                    BopNodeId = table.Column<Guid>(nullable: false),
                    Model = table.Column<string>(nullable: true),
                    ModelName = table.Column<string>(nullable: true),
                    LotNo = table.Column<string>(nullable: true),
                    DrawingNo = table.Column<string>(nullable: true),
                    StageSign = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileProcessSpecifications", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FileProcessSpecifications_BopNodes_BopNodeId",
                        column: x => x.BopNodeId,
                        principalTable: "BopNodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FileTechniqueTasks",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FileProcessSpecificationId = table.Column<Guid>(nullable: false),
                    BopDescId = table.Column<string>(nullable: true),
                    BopNodeId = table.Column<string>(nullable: true),
                    OriginalPPSId = table.Column<string>(nullable: true),
                    TechniqueName = table.Column<string>(nullable: true),
                    TechniqueNumber = table.Column<string>(nullable: true),
                    TechniqueAuthor = table.Column<string>(nullable: true),
                    CompileTime = table.Column<DateTime>(nullable: false),
                    SystemCode = table.Column<string>(nullable: true),
                    ProductCode = table.Column<string>(nullable: true),
                    ModuleCode = table.Column<string>(nullable: true),
                    ModuleName = table.Column<string>(nullable: true),
                    StageSign = table.Column<int>(nullable: false),
                    TechniqueType = table.Column<int>(nullable: false),
                    TechniqueCharacter = table.Column<string>(nullable: true),
                    Shape = table.Column<int>(nullable: false),
                    SecretDegree = table.Column<int>(nullable: false),
                    UseUnit = table.Column<string>(nullable: true),
                    UseTime = table.Column<string>(nullable: true),
                    BasisFile = table.Column<string>(nullable: true),
                    IssueUnit = table.Column<string>(nullable: true),
                    TechniqueExplain = table.Column<string>(nullable: true),
                    Remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileTechniqueTasks", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FileTechniqueTasks_FileProcessSpecifications_FileProcessSpecificationId",
                        column: x => x.FileProcessSpecificationId,
                        principalTable: "FileProcessSpecifications",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FileProcessess",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FileTechniqueTaskId = table.Column<Guid>(nullable: false),
                    RemarkTechniqueEntityId = table.Column<string>(nullable: true),
                    OriginalProcessesId = table.Column<string>(nullable: true),
                    ProcessesExplain = table.Column<string>(nullable: true),
                    ProcessesSequence = table.Column<int>(nullable: false),
                    ProcessesName = table.Column<string>(nullable: true),
                    ProcessesWorking = table.Column<decimal>(nullable: false),
                    ProcessesType = table.Column<string>(nullable: true),
                    ProcessesCharacteristic = table.Column<string>(nullable: true),
                    F_HtmlContent = table.Column<string>(nullable: true),
                    URL = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileProcessess", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FileProcessess_FileTechniqueTasks_FileTechniqueTaskId",
                        column: x => x.FileTechniqueTaskId,
                        principalTable: "FileTechniqueTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "FileWorkSteps",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    FileTechniqueTaskId = table.Column<Guid>(nullable: false),
                    FileProcessesId = table.Column<Guid>(nullable: false),
                    TechniqueEntityId = table.Column<string>(nullable: true),
                    ProcessesEntityId = table.Column<string>(nullable: true),
                    OriginalWorkStepEntityId = table.Column<string>(nullable: true),
                    WorkStepNumber = table.Column<string>(nullable: true),
                    WorkStepName = table.Column<string>(nullable: true),
                    WorkStepSerialName = table.Column<string>(nullable: true),
                    WorkStepContent = table.Column<string>(nullable: true),
                    WorkStepWorking = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FileWorkSteps", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FileWorkSteps_FileProcessess_FileProcessesId",
                        column: x => x.FileProcessesId,
                        principalTable: "FileProcessess",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BopNodes_BopNodeId",
                table: "BopNodes",
                column: "BopNodeId");

            migrationBuilder.CreateIndex(
                name: "IX_BopNodes_BopTreeId",
                table: "BopNodes",
                column: "BopTreeId");

            migrationBuilder.CreateIndex(
                name: "IX_FileProcessess_FileTechniqueTaskId",
                table: "FileProcessess",
                column: "FileTechniqueTaskId");

            migrationBuilder.CreateIndex(
                name: "IX_FileProcessSpecifications_BopNodeId",
                table: "FileProcessSpecifications",
                column: "BopNodeId");

            migrationBuilder.CreateIndex(
                name: "IX_FileTechniqueTasks_FileProcessSpecificationId",
                table: "FileTechniqueTasks",
                column: "FileProcessSpecificationId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_FileWorkSteps_FileProcessesId",
                table: "FileWorkSteps",
                column: "FileProcessesId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "FileTableDatas");

            migrationBuilder.DropTable(
                name: "FileTables");

            migrationBuilder.DropTable(
                name: "FileWorkSteps");

            migrationBuilder.DropTable(
                name: "StructColumnTypes");

            migrationBuilder.DropTable(
                name: "FileProcessess");

            migrationBuilder.DropTable(
                name: "FileTechniqueTasks");

            migrationBuilder.DropTable(
                name: "FileProcessSpecifications");

            migrationBuilder.DropTable(
                name: "BopNodes");

            migrationBuilder.DropTable(
                name: "BopTrees");
        }
    }
}
